{VERSION V1.0-001   05-JUN-2000}
unit MarsRegBin;

interface

function GetASIASubsystemPath(SName : String) : String;
procedure SetASIASubSystemPath (SName : String; Value : String);
function GetDescFilePath(SName : String) : String;
procedure SetDescFilePath(SName : String; Value : String);
function GetExtFilePath(SName : String) : String;
procedure SetExtFilePath(SName : String; Value : String);
function  GetSetting(SName : String) : String;
procedure  SetSetting(SName : String; Value : String);
function  GetIntSetting(SName : String; ADefault : Integer) : Integer;
procedure  SetIntSetting(SName : String; Value : Integer);
function  ARSShowMessage(Msg : String) : Boolean;
procedure  ARSShowDocErrorMessage (Msg : String; DocNo : String; Contractor : Integer; TableName : String);

implementation
uses
  Windows, Registry, MarsCnst, SysUtils, arsDialog, arsDocError, Forms;

function GetASIASubsystemPath(SName : String) : String;
var KeyName : String;	
begin
  Result := '';	
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      if not OpenKey(AppRootKey, False) then
        Exit;
      KeyName:=AppRootKey + '\Subsystems\'+SName;
      if not OpenKey(KeyName, False) then
      	Exit;
      Result :=ReadString('Path');
    finally
      Free;
    end;
end;

procedure SetASIASubSystemPath (SName : String; Value : String);
var KeyName : String;	
begin
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      OpenKey(AppRootKey, True);
      KeyName:=AppRootKey + '\Subsystems\'+SName;
      if not OpenKey(KeyName, True) then
      	Exit;
      WriteString('Path', Value);
    finally
      Free;
    end;
end;

function GetDescFilePath(SName : String) : String;
var KeyName : String;
begin
  Result := '';
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      if not OpenKey(AppRootKey, False) then
        Exit;
      KeyName:=AppRootKey + '\DescFiles\'+SName;
      if not OpenKey(KeyName, False) then
      	Exit;
      Result :=ReadString('Path');
    finally
      Free;
    end;
end;

procedure SetDescFilePath (SName : String; Value : String);
var KeyName : String;
begin
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      OpenKey(AppRootKey, True);
      KeyName:=AppRootKey + '\DescFiles\'+SName;
      if not OpenKey(KeyName, True) then
      	Exit;
      WriteString('Path', Value);
    finally
      Free;
    end;
end;

function GetExtFilePath(SName : String) : String;
var KeyName : String;
begin
  Result := '';
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      if not OpenKey(AppRootKey, False) then
        Exit;
      KeyName:=AppRootKey + '\ExtFiles\'+SName;
      if not OpenKey(KeyName, False) then
      	Exit;
      Result :=ReadString('Path');
    finally
      Free;
    end;
end;

procedure SetExtFilePath(SName : String; Value : String);
var KeyName : String;
begin
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      OpenKey(AppRootKey, True);
      KeyName:=AppRootKey + '\ExtFiles\'+SName;
      if not OpenKey(KeyName, True) then
      	Exit;
      WriteString('Path', Value);
    finally
      Free;
    end;
end;

function  GetSetting(SName : String) : String;
var KeyName : String;
begin
  Result := '';
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      if not OpenKey(AppRootKey, False) then
        Exit;
      KeyName:=AppRootKey + '\Settings\'+SName;
      if not OpenKey(KeyName, False) then
      	Exit;
      Result :=ReadString('Value');
    finally
      Free;
    end;
end;

procedure  SetSetting(SName : String; Value : String);
var KeyName : String;
begin
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      OpenKey(AppRootKey, True);
      KeyName:=AppRootKey + '\Settings\'+SName;
      if not OpenKey(KeyName, True) then
      	Exit;
      WriteString('Value', Value);
    finally
      Free;
    end;
end;

function  GetIntSetting(SName : String; ADefault : Integer) : Integer;
var KeyName : String;
begin
  Result := ADefault;
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      if not OpenKey(AppRootKey, False) then
        Exit;
      KeyName:=AppRootKey + '\Settings\'+SName;
      if not OpenKey(KeyName, False) then
      	Exit;
      Result :=ReadInteger('Value');
    finally
      Free;
    end;
end;

procedure  SetIntSetting(SName : String; Value : Integer);
var KeyName : String;
begin
  with TRegistry.Create do
    try
      RootKey:=HKEY_CURRENT_USER;
      OpenKey(AppRootKey, True);
      KeyName:=AppRootKey + '\Settings\'+SName;
      if not OpenKey(KeyName, True) then
      	Exit;
      WriteInteger('Value', Value);
    finally
      Free;
    end;
end;

function  ARSShowMessage(Msg : String) : Boolean;
begin
  with frmARSDialog do begin
    lbMessage.Caption := Msg;
    ShowModal();
    Result := NOT CheckBox1.Checked;
  end;
end;

procedure  ARSShowDocErrorMessage (Msg : String; DocNo : String; Contractor : Integer; TableName : String);
begin
  with TfrmARSDocError.Create(Application) do begin
    lbMessage.Caption := Msg;
    ATDNR := DocNo;
    AContractor := Contractor;
    ATableName := TableName;
    try
      ShowModal();
    finally
      Free();
    end;
  end;
end;

end.
